package com.wubotao.multithreading;

import java.util.concurrent.locks.Lock;

/**
 * @说明 父亲类，只挣钱
 */
public class Producer implements Runnable {
	BankCard bc = null;
	Lock lock = null;

	Producer(BankCard bc, Lock lock) {
		this.bc = bc;
		this.lock = lock;
	}

	public void run() {
		try {
			while (true) {
				try {
					lock.lock();
					System.out.print("父亲要存钱，现在余额：" + bc.getBalance() + "\t");
					bc.setBalance(bc.getBalance() + 5000);
					System.out.println("父亲存入5000元，现在余额：" + bc.getBalance());
				} finally {
					lock.unlock();
				}

				Thread.sleep(3 * 1000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
